//
//  DataViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 14-12-30.
//  Copyright (c) 2014年 RuiBen. All rights reserved.
//

#import "ScanViewController.h"

@interface ScanViewController ()
{
     NSUInteger previousSelectedIndex;
}
@end

@implementation ScanViewController
@synthesize scanViewControllers = _scanViewControllers;
-(void)viewWillAppear:(BOOL)animated
{
    [Global setHomeCustomID:5];
    [self setSelectedIndex:0];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}
- (void)setSelectedIndex:(NSUInteger)selectedIndex
{
    if (selectedIndex<[self.scanViewControllers count]) {
        if (previousSelectedIndex != NSNotFound)
        {
            UIViewController *previousViewController = [self.scanViewControllers objectAtIndex:previousSelectedIndex];
            [previousViewController.view removeFromSuperview];
            [previousViewController removeFromParentViewController];
        }
        
        UIViewController *selectedViewController = [self.scanViewControllers objectAtIndex:selectedIndex];
        [self addChildViewController:selectedViewController];
        selectedViewController.view.frame = CGRectMake(0, 0, DEFAULT_FirstLevelView_WIDTH, DEFAULT_FirstLevelView_HEIGHT);
        selectedViewController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
        [self.view addSubview:selectedViewController.view];
        // remove previously selected view controller (if any)
        previousSelectedIndex=selectedIndex;
    }
    
}
-(void)scanStockBack
{
    [self setSelectedIndex:0];
}
-(void)productItemDetailBackBtnClick
{
   
    [self setSelectedIndex:0];
}
-(void)scanMemberBack
{
    [self setSelectedIndex:0];
}
-(void)scanMember
{
    [self setSelectedIndex:3];
}
-(void)scanShopShopCartClick
{
    [self setSelectedIndex:4];
}
-(void)scanShop
{
    [self setSelectedIndex:1];
}
-(void)scanShopShopCartBackClick
{
     [self setSelectedIndex:1];
}
-(void)scanStock
{
    [self setSelectedIndex:2];
}
-(void)setScanViewControllers:(NSArray *)viewControllers
{
    _scanViewControllers = [viewControllers copy];
    previousSelectedIndex=NSNotFound;
    // create tab bar items
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
